package com.zzlzd.drp.config;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.SerializerFeature;

import java.io.Serializable;

public class ResponseInfo implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 1886106011131539131L;

    private String code;
    private String msg;
    @JSONField(serialzeFeatures = {SerializerFeature.WriteMapNullValue})
    private Object data;

    /* set and get */
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    /* 构造 */
    public ResponseInfo() {
        super();
        // TODO Auto-generated constructor stub
    }

    public ResponseInfo(String code, String msg, Object data) {
        super();
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 默认成功或者失败,无数据
     * @param resultCode
     */
    public ResponseInfo(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMessage();
    }

    /**
     * 枚举结果以及获取数据
     * @param resultCode
     */
    public ResponseInfo(ResultCode resultCode, String msg) {
        this.code = resultCode.getCode();
        this.msg = msg;
    }

    public ResponseInfo(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 枚举结果以及获取数据
     * @param resultCode
     * @param data
     */
    public ResponseInfo(ResultCode resultCode, Object data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMessage();
        this.data = data;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

}
